using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.Hr.Attendance;
using HengTong.Model.Db.Hr.Attendance.Rule;


namespace HengTong.ViewModel.Hr.SysAttendanceShiftVms
{
    public partial class SysAttendanceShiftListVm : BaseListVm<SysAttendanceShiftView, SysAttendanceShiftSearcher>
    {

        protected override IEnumerable<IGridColumn<SysAttendanceShiftView>> InitGridHeader()
        {
            return new List<GridColumn<SysAttendanceShiftView>>{
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.DisplayColor),
                this.MakeGridHeader(x => x.Tag),
                this.MakeGridHeader(x => x.IsEnabled),
                this.MakeGridHeader(x => x.Remark),
                this.MakeGridHeader(x => x.WorkStartDayOffset),
                this.MakeGridHeader(x => x.WorkStartTime),
                this.MakeGridHeader(x => x.WorkStartPunchStartDayOffset),
                this.MakeGridHeader(x => x.WorkStartPunchStartTime),
                this.MakeGridHeader(x => x.WorkStartPunchEndDayOffset),
                this.MakeGridHeader(x => x.WorkStartPunchEndTime),
                this.MakeGridHeader(x => x.WorkEndDayOffset),
                this.MakeGridHeader(x => x.WorkEndTime),
                this.MakeGridHeader(x => x.WorkEndPunchStartDayOffset),
                this.MakeGridHeader(x => x.WorkEndPunchStartTime),
                this.MakeGridHeader(x => x.WorkEndPunchEndDayOffset),
                this.MakeGridHeader(x => x.WorkEndPunchEndTime),
                this.MakeGridHeader(x => x.AttendanceViolationRuleEnabled),
                this.MakeGridHeader(x => x.LateMinutesThreshold),
                this.MakeGridHeader(x => x.EarlyLeaveMinutesThreshold),
                this.MakeGridHeader(x => x.AbsenceByLateMinutesThreshold),
                this.MakeGridHeader(x => x.AbsenceByEarlyLeaveMinutesThreshold),
                this.MakeGridHeader(x => x.AbsenceByTotalDeviationMinutesThreshold),
                this.MakeGridHeader(x => x.StandardWorkMinutes),
                this.MakeGridHeader(x => x.AttendanceDays),
                this.MakeGridHeader(x => x.SubsidyRuleEnabled),
                this.MakeGridHeader(x => x.IsHolidayScheduled),
                this.MakeGridHeader(x => x.WorkDays),
                this.MakeGridHeader(x => x.Order),
                this.MakeGridHeader(x => x.IsDefault),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysAttendanceShiftView> GetSearchQuery()
        {
            var query = DC.Set<SysAttendanceShift>()
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckEqual(Searcher.IsEnabled, x=>x.IsEnabled)
                .Select(x => new SysAttendanceShiftView
                {
				    ID = x.ID,
                    Name = x.Name,
                    DisplayColor = x.DisplayColor,
                    Tag = x.Tag,
                    IsEnabled = x.IsEnabled,
                    Remark = x.Remark,
                    WorkStartDayOffset = x.WorkStartDayOffset,
                    WorkStartTime = x.WorkStartTime,
                    WorkStartPunchStartDayOffset = x.WorkStartPunchStartDayOffset,
                    WorkStartPunchStartTime = x.WorkStartPunchStartTime,
                    WorkStartPunchEndDayOffset = x.WorkStartPunchEndDayOffset,
                    WorkStartPunchEndTime = x.WorkStartPunchEndTime,
                    WorkEndDayOffset = x.WorkEndDayOffset,
                    WorkEndTime = x.WorkEndTime,
                    WorkEndPunchStartDayOffset = x.WorkEndPunchStartDayOffset,
                    WorkEndPunchStartTime = x.WorkEndPunchStartTime,
                    WorkEndPunchEndDayOffset = x.WorkEndPunchEndDayOffset,
                    WorkEndPunchEndTime = x.WorkEndPunchEndTime,
                    AttendanceViolationRuleEnabled = x.AttendanceViolationRuleEnabled,
                    LateMinutesThreshold = x.LateMinutesThreshold,
                    EarlyLeaveMinutesThreshold = x.EarlyLeaveMinutesThreshold,
                    AbsenceByLateMinutesThreshold = x.AbsenceByLateMinutesThreshold,
                    AbsenceByEarlyLeaveMinutesThreshold = x.AbsenceByEarlyLeaveMinutesThreshold,
                    AbsenceByTotalDeviationMinutesThreshold = x.AbsenceByTotalDeviationMinutesThreshold,
                    StandardWorkMinutes = x.StandardWorkMinutes,
                    AttendanceDays = x.AttendanceDays,
                    SubsidyRuleEnabled = x.SubsidyRuleEnabled,
                    IsHolidayScheduled = x.IsHolidayScheduled,
                    WorkDays = x.WorkDays,
                    Order = x.Order,
                    IsDefault = x.IsDefault
                })
                .OrderBy(x => x.Order ?? 99.99m)
                .ThenBy(x => x.ID);
            return query;
        }
    }

    public class SysAttendanceShiftView : SysAttendanceShift{
        
    }
}
